package com.haocjia.esdemo.highapi.index.service;

import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.common.settings.Setting;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

public interface IIndexService {

    /**
     * 创建一个默认的索引
     *
     * @param index
     * @return
     * @throws IOException
     */
    CreateIndexResponse createIndex(String index) throws IOException;

    /**
     * 创建索引 传入mapping
     *
     * @param index
     * @param mapping
     * @return
     * @throws IOException
     */
    CreateIndexResponse createIndex(String index, Map<String, Object> mapping) throws IOException;

    /**
     * 创建索引 有分片和副本设置
     *
     * @param index
     * @param mapping
     * @param shards
     * @param replicas
     * @return
     * @throws IOException
     */
    CreateIndexResponse createIndex(String index, Map<String, Object> mapping, Integer shards, Integer replicas) throws IOException;


    /**
     * 创建索引 设置副本和 分片数量
     *
     * @param index
     * @param shards
     * @param replicas
     * @return
     * @throws IOException
     */
    CreateIndexResponse createIndex(String index, Integer shards, Integer replicas) throws IOException;

    /**
     * 删除索引
     *
     * @param index
     * @return
     * @throws IOException
     */
    AcknowledgedResponse deleteIndex(String index) throws IOException;

    /**
     * 判断索引是否存在
     *
     * @param index
     * @return
     */
    Boolean exists(String index) throws IOException;

    /**
     * 开放索引
     *
     * @param index
     * @return
     */
    OpenIndexResponse openIndex(String... index) throws IOException;

    /**
     * 关闭索引
     *
     * @param index
     * @return
     * @throws IOException
     */
    AcknowledgedResponse closeIndex(String index) throws IOException;

    /**
     * 更新mapping
     *
     * @param index
     * @param mapping
     * @return
     * @throws IOException
     */
    AcknowledgedResponse updateMapping(String index, Map<String, Object> mapping) throws IOException;

    IndexResponse add(String index, Object obj);
}
